define(['jQuery', 'common', 'layer', 'validateForm'], function($, common, layer, validateForm) {
	return {
		initPage: function() {
			this.initEvent();
		},
		initEvent: function() {
			// message
			if ($("#div-message").text() != "") {
				layer.msg($("#div-message").text());
			} 
			var that_ = this;
			$("#loginForm").keydown(function() {
				var evt=evt?evt:window.event;
				if (evt && evt.keyCode==13){
				    that_.validCode();
				}
			});
			$("#loginBtn").bind("click", function() {
				that_.validCode();
			});
		},
		validCode: function() {
			var that_ = this;
			var validateCode = $("#validateCode").val();
			if (validateCode == null || validateCode == "") {
			    layer.msg("请输入验证码");
			    return;
			}
			var url = ctx + "/SecurityController/validateCode.do";
			var params = {"validateCode":validateCode};
			common.postNetwork(url, params, function(data) {
				if (typeof data == "undefined") {
				    layer.msg("后台错误！");
				    return;
				} else if(data =='0'){
				    layer.msg("验证码不正确！");
					$("#validateCode").val("");
					return;
				}else{
					that_.login();
				}
			});
			
		},
		login: function() {
			if(!$("#loginForm").validateForm()){
       			return;
       		}
       		$("#param_password").val(hex_md5($("#pwd").val()));
   	    	$("#loginForm").attr("action", ctx +"/SecurityController/login.do");
  	     	$("#loginForm").submit();
		}
	}
});